<template>
  <div class="ml20">
    <div class="f18">您正在试图访问或操作个人敏感信息，请再次确认输入管理员密码：</div>
    <div class="mt20 inpt">
      <el-input v-model="password" placeholder="请输入密码"></el-input>
    </div>
    <div class="row mt30">
      <el-button class="mt20" size="medium" @click="$emit('close')">取消</el-button>
      <el-button class="mt20" type="primary" size="medium" @click="getCheck">验证</el-button>
    </div>
  </div>
</template>

<script>
import Rsa from '@/utils/rsa.js';
import axios from 'axios';
export default {
  data() {
    return {
      password: ''
    };
  },
  methods: {
    async getCheck() {
      let username = sessionStorage.getItem('account');
      let keyiv = JSON.parse(sessionStorage.getItem('keyiv'));
      let param = {
        username,
        password: this.$md5(this.password)
      };
      let rsa = new Rsa(keyiv);
      let paramStr = JSON.stringify(param);
      let AES = rsa.encrypt(paramStr);
      let res = await this.$api.user.get_sensitive_auth({ auth: rsa.RSAencrypt(AES) });
      if (res.code === 0 && res.data) {
        sessionStorage.setItem('CheckEncryption', res.data);
        this.$emit('close');
        this.$message({
          message: '验证成功',
          type: 'success'
        });
        return;
      }
      let tqRes = await this.$api.user.tianque_gateway({ username: username,password:this.$md5(this.password)});
      if (tqRes.ss.code === 200 && tqRes.data) {
        sessionStorage.setItem('CheckEncryption', tqRes.data);
        this.$emit('close');
        this.$message({
          message: '验证成功',
          type: 'success'
        });
        return;
      }
      this.$message.error('验证失败');
    }
  }
};
</script>

<style scoped>
.inpt {
  width: 70%;
}
</style>
